package org.dfzt.modules.online.cgform.util;

import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.io.IOException;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.SQLException;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.dfzt.common.exception.SpringBootException;
import org.dfzt.common.system.service.ISysBaseAPI;
import org.dfzt.common.system.query.MatchTypeEnum;
import org.dfzt.common.system.query.QueryGenerator;
import org.dfzt.common.system.query.QueryRuleEnum;
import org.dfzt.common.system.vo.LoginUser;
import org.dfzt.common.system.vo.SysPermissionDataRuleModel;
import org.dfzt.common.util.*;
import org.dfzt.common.util.jsonschema.BaseColumn;
import org.dfzt.common.util.jsonschema.CommonProperty;
import org.dfzt.common.util.jsonschema.JsonSchemaDescrip;
import org.dfzt.common.util.jsonschema.JsonschemaUtil;
import org.dfzt.common.util.jsonschema.validate.*;
import org.dfzt.modules.online.cgform.entity.*;
import org.dfzt.modules.online.cgform.enums.CgformValidPatternEnum;
import org.dfzt.modules.online.cgform.mapper.OnlCgformHeadMapper;
import org.dfzt.modules.online.cgform.model.Field;
import org.dfzt.modules.online.cgform.service.IOnlCgformFieldService;
import org.dfzt.modules.online.config.exception.DBException;
import org.jeecgframework.core.util.ApplicationContextUtil;
import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity;

import javax.servlet.http.HttpServletRequest;

import static java.nio.charset.StandardCharsets.*;

public class b {
    private static final Logger as = LoggerFactory.getLogger(b.class);


    public static final String SELECT = "SELECT ";


    public static final String FROM = " FROM ";


    public static final String AND = " AND ";


    public static final String LIKE = " like ";


    public static final String COUNT = " COUNT(*) ";


    public static final String WHERE_1_1 = " where 1=1  ";


    public static final String ORDER_BY = " ORDER BY ";


    public static final String ASC = "asc";


    public static final String DESC = "desc";


    public static final String eq = "=";


    public static final String notEq = "!=";


    public static final String greatEq = ">=";


    public static final String great = ">";


    public static final String letEq = "<=";


    public static final String let = "<";


    public static final String p = "Y";


    public static final String q = "$";


    public static final String CREATE_TIME = "CREATE_TIME";


    public static final String CREATE_BY = "CREATE_BY";


    public static final String UPDATE_TIME = "UPDATE_TIME";


    public static final String UPDATE_BY = "UPDATE_BY";


    public static final String SYS_ORG_CODE = "SYS_ORG_CODE";


    public static final int w = 2;


    public static final String x = "'";


    public static final String y = "N";


    public static final String z = ",";


    public static final String SINGLE = "single";


    public static final String ID = "id";


    public static final String BPM_STATUS = "bpm_status";


    public static final String D = "1";


    public static final String FORCE = "force";


    public static final String NORMAL = "normal";


    public static final String SWITCH = "switch";


    public static final String POPUP = "popup";


    public static final String IMAGE = "image";


    public static final String SEL_TREE = "sel_tree";


    public static final String CAT_TREE = "cat_tree";


    public static final String LINK_DOWN = "link_down";


    public static final String SYS_USER = "SYS_USER";


    public static final String REALNAME = "REALNAME";


    public static final String USERNAME = "USERNAME";


    public static final String SYS_DEPART = "SYS_DEPART";


    public static final String DEPART_NAME = "DEPART_NAME";


    public static final String ID1 = "ID";


    public static final String SYS_CATEGORY = "SYS_CATEGORY";


    public static final String NAME = "NAME";


    public static final String CODE = "CODE";


    public static final String ID2 = "ID";


    public static final String PID = "PID";


    public static final String HAS_CHILD = "HAS_CHILD";


    public static final String SEL_SEARCH = "sel_search";


    public static final String SUB_TABLE_DESIGN = "sub-table-design_";


    public static final String IMPORT = "import";


    public static final String EXPORT = "export";


    public static final String QUERY = "query";


    public static final String FORM = "form";


    public static final String LIST = "list";


    public static final String af = "1";


    public static final String START = "start";


    public static final String ERP = "erp";


    public static final String EXPORT_SINGLE_ONLY = "exportSingleOnly";


    public static final String IS_SINGLE_TABLE_IMPORT = "isSingleTableImport";


    public static final String FOREIGN_KEYS = "foreignKeys";


    public static final int al = 1;


    public static final int am = 2;


    public static final int an = 0;


    public static final int ao = 1;


    public static final String ap = "1";


    public static final String ID3 = "id";


    public static final String CENTER = "center";


    private static final String at = "beforeAdd,beforeEdit,afterAdd,afterEdit,beforeDelete,afterDelete,mounted,created";


    private static String au;


    public static void a(String paramString, List<OnlCgformField> paramList, StringBuffer paramStringBuffer) {
        if (paramList == null || paramList.size() == 0) {
            paramStringBuffer.append("SELECT id");
        } else {
            paramStringBuffer.append("SELECT ");
            int i1 = paramList.size();
            boolean bool = false;
            for (byte b1 = 0; b1 < i1; b1++) {
                OnlCgformField onlCgformField = (OnlCgformField) paramList.get(b1);
                if ("id".equals(onlCgformField.getDbFieldName())) {
                    bool = true;
                }

                if ("cat_tree".equals(onlCgformField.getFieldShowType()) && oConvertUtils.isNotEmpty(onlCgformField.getDictText())) {
                    paramStringBuffer.append(onlCgformField.getDictText() + ",");
                }

                if (b1 == i1 - 1) {
                    paramStringBuffer.append(onlCgformField.getDbFieldName() + " ");
                } else {
                    paramStringBuffer.append(onlCgformField.getDbFieldName() + ",");
                }
            }
            if (!bool) {
                paramStringBuffer.append(",id");
            }
        }
        paramStringBuffer.append(" FROM " + f(paramString));
    }


    public static String a(String paramString) {
        return " to_date('" + paramString + "','yyyy-MM-dd HH24:mi:ss')";
    }


    public static String b(String paramString) {
        return " to_date('" + paramString + "','yyyy-MM-dd')";
    }


    public static boolean c(String paramString) {
        if ("list".equals(paramString)) {
            return true;
        }
        if ("radio".equals(paramString)) {
            return true;
        }
        if ("checkbox".equals(paramString)) {
            return true;
        }
        if ("list_multi".equals(paramString)) {
            return true;
        }
        return false;
    }


    public static String a(List<OnlCgformField> paramList1, Map<String, Object> paramMap, List<String> paramList2) {
        StringBuffer stringBuffer = new StringBuffer();
        String str = "";
        try {
            str = org.dfzt.modules.online.config.util.d.getDatabaseType();
        } catch (SQLException sQLException) {
            sQLException.printStackTrace();
        } catch (DBException dBException) {
            dBException.printStackTrace();
        }

        Map<String, SysPermissionDataRuleModel> map = QueryGenerator.getRuleMap();

        for (String str1 : map.keySet()) {
            if (oConvertUtils.isNotEmpty(str1) && str1.startsWith("SQL_RULES_COLUMN")) {
                stringBuffer.append(" AND (" + QueryGenerator.getSqlRuleValue(((SysPermissionDataRuleModel) map.get(str1)).getRuleValue()) + ")");
            }
        }
        for (OnlCgformField onlCgformField : paramList1) {
            String str1 = onlCgformField.getDbFieldName();
            String str2 = onlCgformField.getDbType();

            if (map.containsKey(str1)) {
                a(str, (SysPermissionDataRuleModel) map.get(str1), str1, str2, stringBuffer);
            }
            if (map.containsKey(oConvertUtils.camelNames(str1))) {
                a(str, (SysPermissionDataRuleModel) map.get(str1), str1, str2, stringBuffer);
            }


            if (paramList2 != null && paramList2.contains(str1)) {
                onlCgformField.setIsQuery(Integer.valueOf(1));
                onlCgformField.setQueryMode("single");
            }


            if (oConvertUtils.isNotEmpty(onlCgformField.getMainField()) && oConvertUtils.isNotEmpty(onlCgformField.getMainTable())) {
                onlCgformField.setIsQuery(Integer.valueOf(1));
                onlCgformField.setQueryMode("single");
            }


            if (1 == onlCgformField.getIsQuery().intValue()) {

                if ("single".equals(onlCgformField.getQueryMode())) {
                    Object object = paramMap.get(str1);
                    if (object != null) {
                        if ("ORACLE".equals(str) && str2.toLowerCase().indexOf("date") >= 0) {
                            stringBuffer.append(" AND " + str1 + "=" + a(object.toString()));
                            continue;
                        }
                        boolean bool = !org.dfzt.modules.online.cgform.util.i.a(str2);
                        String str3 = QueryGenerator.getSingleQueryConditionSql(str1, "", object, bool);
                        stringBuffer.append(" AND " + str3);
                    }

                    continue;
                }
                Object object1 = paramMap.get(str1 + "_begin");
                if (object1 != null) {
                    stringBuffer.append(" AND " + str1 + ">=");
                    if (org.dfzt.modules.online.cgform.util.i.a(str2)) {

                        stringBuffer.append(object1.toString());
                    } else if ("ORACLE".equals(str) && str2.toLowerCase().indexOf("date") >= 0) {
                        stringBuffer.append(a(object1.toString()));
                    } else {

                        stringBuffer.append("'" + object1.toString() + "'");
                    }
                }
                Object object2 = paramMap.get(str1 + "_end");
                if (object2 != null) {
                    stringBuffer.append(" AND " + str1 + "<=");
                    if (org.dfzt.modules.online.cgform.util.i.a(str2)) {
                        stringBuffer.append(object2.toString());
                        continue;
                    }
                    if ("ORACLE".equals(str) && str2.toLowerCase().indexOf("date") >= 0) {
                        stringBuffer.append(a(object2.toString()));
                        continue;
                    }
                    stringBuffer.append("'" + object2.toString() + "'");
                }
            }
        }


        return stringBuffer.toString();
    }


    public static String a(Map<String, Object> paramMap) {
        Object object1 = paramMap.get("superQueryParams");
        if (object1 == null || StringUtils.isBlank(object1.toString())) {
            return "";
        }
        IOnlCgformFieldService iOnlCgformFieldService = (IOnlCgformFieldService) SpringContextUtils.getBean(IOnlCgformFieldService.class);
        String str = null;
        try {
            str = URLDecoder.decode(object1.toString(), "UTF-8");
        } catch (UnsupportedEncodingException unsupportedEncodingException) {
            unsupportedEncodingException.printStackTrace();
            return "";
        }
        JSONArray jSONArray = JSONArray.parseArray(str);

        Object object2 = paramMap.get("superQueryMatchType");
        MatchTypeEnum matchTypeEnum = MatchTypeEnum.getByValue(object2);
        if (matchTypeEnum == null) {
            matchTypeEnum = MatchTypeEnum.AND;
        }

        HashMap hashMap = new HashMap();

        StringBuilder stringBuilder = (new StringBuilder(" AND ")).append("(");
        for (byte b1 = 0; b1 < jSONArray.size(); b1++) {
            JSONObject jSONObject = jSONArray.getJSONObject(b1);
            String str1 = jSONObject.getString("field");
            String[] arrayOfString = str1.split(",");

            if (arrayOfString.length == 1) {
                a(stringBuilder, str1, jSONObject, matchTypeEnum, null, (b1 == 0));
            } else if (arrayOfString.length == 2) {

                String str2 = arrayOfString[0];
                String str3 = arrayOfString[1];
                JSONObject jSONObject1 = (JSONObject) hashMap.get(str2);
                if (jSONObject1 == null) {
                    List<OnlCgformField> list = iOnlCgformFieldService.queryFormFieldsByTableName(str2);
                    jSONObject1 = new JSONObject(3);
                    for (OnlCgformField onlCgformField : list) {
                        if (StringUtils.isNotBlank(onlCgformField.getMainTable())) {
                            jSONObject1.put("subTableName", str2);
                            jSONObject1.put("subField", onlCgformField.getDbFieldName());
                            jSONObject1.put("mainTable", onlCgformField.getMainTable());
                            jSONObject1.put("mainField", onlCgformField.getMainField());
                        }
                    }
                    hashMap.put(str2, jSONObject1);
                }
                a(stringBuilder, str3, jSONObject, matchTypeEnum, jSONObject1, (b1 == 0));
            }
        }
        return stringBuilder.append(")").toString();
    }


    private static void a(StringBuilder paramStringBuilder, String paramString, JSONObject paramJSONObject1, MatchTypeEnum paramMatchTypeEnum, JSONObject paramJSONObject2, boolean paramBoolean) {
        if (!paramBoolean) {
            paramStringBuilder.append(" ").append(paramMatchTypeEnum.getValue()).append(" ");
        }
        String str1 = paramJSONObject1.getString("type");
        String str2 = paramJSONObject1.getString("val");
        String str3 = a(str1, str2);
        QueryRuleEnum queryRuleEnum = QueryRuleEnum.getByValue(paramJSONObject1.getString("rule"));
        if (queryRuleEnum == null) {
            queryRuleEnum = QueryRuleEnum.EQ;
        }

        if (paramJSONObject2 != null) {
            String str4 = paramJSONObject2.getString("subTableName");
            String str5 = paramJSONObject2.getString("subField");
            String str6 = paramJSONObject2.getString("mainTable");
            String str7 = paramJSONObject2.getString("mainField");
            paramStringBuilder.append("(").append(str7).append(" IN (SELECT ").append(str5).append(" FROM ").append(str4).append(" WHERE ").append(paramString);
            a(paramStringBuilder, queryRuleEnum, str2, str3, str1);
            paramStringBuilder.append("))");
        } else {
            paramStringBuilder.append(paramString);
            a(paramStringBuilder, queryRuleEnum, str2, str3, str1);
        }
    }

    private static void a(StringBuilder paramStringBuilder, QueryRuleEnum paramQueryRuleEnum, String paramString1, String paramString2, String paramString3) {
        byte b1;
        String[] arrayOfString;
        if ("date".equals(paramString3) &&
                "ORACLE".equalsIgnoreCase(getDatabseType())) {
            paramString2 = paramString2.replace("'", "");
            if (paramString2.length() == 10) {
                paramString2 = b(paramString2);
            } else {
                paramString2 = a(paramString2);
            }
        }

        //todo 注释switch 选择器有问题 fr
        /*switch (null.a[paramQueryRuleEnum.ordinal()]) {
            case 1:
                paramStringBuilder.append(">").append(paramString2);
                return;
            case 2:
                paramStringBuilder.append(">=").append(paramString2);
                return;
            case 3:
                paramStringBuilder.append("<").append(paramString2);
                return;
            case 4:
                paramStringBuilder.append("<=").append(paramString2);
                return;
            case 5:
                paramStringBuilder.append("!=").append(paramString2);
                return;
            case 6:
                paramStringBuilder.append(" IN (");
                arrayOfString = paramString1.split(",");
                for (b1 = 0; b1 < arrayOfString.length; b1++) {
                    String str = arrayOfString[b1];
                    if (StringUtils.isNotBlank(str)) {
                        String str1 = a(paramString3, str);
                        paramStringBuilder.append(str1);
                        if (b1 < arrayOfString.length - 1) {
                            paramStringBuilder.append(",");
                        }
                    }
                }
                paramStringBuilder.append(")");
                return;
            case 7:
                paramStringBuilder.append(" like ").append("N").append("'").append("%").append(paramString1).append("%").append("'");
                return;
            case 8:
                paramStringBuilder.append(" like ").append("N").append("'").append("%").append(paramString1).append("'");
                return;
            case 9:
                paramStringBuilder.append(" like ").append("N").append("'").append(paramString1).append("%").append("'");
                return;
        }*/

        paramStringBuilder.append("=").append(paramString2);
    }


    private static String a(String paramString1, String paramString2) {
        if ("int".equals(paramString1) || "number".equals(paramString1)) {
            return paramString2;
        }
        if ("date".equals(paramString1)) {
            return "'" + paramString2 + "'";
        }
        if ("SQLSERVER".equals(getDatabseType())) {
            return "N'" + paramString2 + "'";
        }
        return "'" + paramString2 + "'";
    }


    public static Map<String, Object> a(HttpServletRequest paramHttpServletRequest) {
        Map map = paramHttpServletRequest.getParameterMap();

        HashMap hashMap = new HashMap();
        Iterator iterator = map.entrySet().iterator();


        String str1 = "";
        String str2 = "";
        Object object = null;
        while (iterator.hasNext()) {
            Map.Entry entry = (Map.Entry) iterator.next();
            str1 = (String) entry.getKey();
            object = entry.getValue();
            if ("_t".equals(str1) || null == object) {
                str2 = "";
            } else if (object instanceof String[]) {
                String[] arrayOfString = (String[]) object;
                for (byte b1 = 0; b1 < arrayOfString.length; b1++) {
                    str2 = arrayOfString[b1] + ",";
                }
                str2 = str2.substring(0, str2.length() - 1);
            } else {
                str2 = object.toString();
            }
            hashMap.put(str1, str2);
        }
        return hashMap;
    }


    public static boolean a(String paramString, List<OnlCgformField> paramList) {
        for (OnlCgformField onlCgformField : paramList) {
            if (paramString.equals(onlCgformField.getDbFieldName())) {
                return true;
            }
        }
        return false;
    }


    public static JSONObject a(List<OnlCgformField> paramList1, List<String> paramList2, Field paramf) {
        JSONObject jSONObject = new JSONObject();
        ArrayList arrayList1 = new ArrayList();
        ArrayList arrayList2 = new ArrayList();
        ISysBaseAPI iSysBaseAPI = (ISysBaseAPI) SpringContextUtils.getBean(ISysBaseAPI.class);
        OnlCgformHeadMapper onlCgformHeadMapper = (OnlCgformHeadMapper) SpringContextUtils.getBean(OnlCgformHeadMapper.class);

        ArrayList arrayList3 = new ArrayList();
        for (OnlCgformField onlCgformField : paramList1) {
            String str1 = onlCgformField.getDbFieldName();
            if ("id".equals(str1)) {
                continue;
            }
            if (arrayList3.contains(str1)) {
                continue;
            }
            String str2 = onlCgformField.getDbFieldTxt();

            if ("1".equals(onlCgformField.getFieldMustInput())) {
                arrayList1.add(str1);
            }
            String fieldShowType = onlCgformField.getFieldShowType();

            CommonProperty commonProperty = null;

            if ("switch".equals(fieldShowType)) {
                commonProperty = new SwitchProperty(str1, str2, onlCgformField.getFieldExtendJson());
            } else if (c(fieldShowType)) {
                List list = new ArrayList();
                if (oConvertUtils.isNotEmpty(onlCgformField.getDictTable())) {
                    list = iSysBaseAPI.queryTableDictItemsByCode(onlCgformField.getDictTable(), onlCgformField.getDictText(), onlCgformField.getDictField());
                } else if (oConvertUtils.isNotEmpty(onlCgformField.getDictField())) {
                    list = iSysBaseAPI.queryDictItemsByCode(onlCgformField.getDictField());
                }
                StringProperty stringProperty1 = new StringProperty(str1, str2, fieldShowType, onlCgformField.getDbLength(), list);
                if (i.a(onlCgformField.getDbType())) {
                    stringProperty1.setType("number");
                }
                commonProperty = stringProperty1;
            } else if (org.dfzt.modules.online.cgform.util.i.a(onlCgformField.getDbType())) {
                NumberProperty numberProperty2 = new NumberProperty(str1, str2, "number");
                if (CgformValidPatternEnum.INTEGER.getType().equals(onlCgformField.getFieldValidType())) {
                    numberProperty2.setPattern(CgformValidPatternEnum.INTEGER.getPattern());
                }
                commonProperty = numberProperty2;

            } else if ("popup".equals(fieldShowType)) {
                PopupProperty popupProperty2 = new PopupProperty(str1, str2, onlCgformField.getDictTable(), onlCgformField.getDictText(), onlCgformField.getDictField());
                String str = onlCgformField.getDictText();
                if (str != null && !str.equals("")) {
                    String[] arrayOfString = str.split(",");
                    for (String str4 : arrayOfString) {
                        if (!a(str4, paramList1)) {


                            HiddenProperty hiddenProperty = new HiddenProperty(str4, str4);
                            hiddenProperty.setOrder(onlCgformField.getOrderNum());
                            arrayList2.add(hiddenProperty);
                        }
                    }
                }
                commonProperty = popupProperty2;
            } else if ("sel_search".equals(fieldShowType)) {
                commonProperty = new DictProperty(str1, str2, onlCgformField.getDictTable(), onlCgformField.getDictField(), onlCgformField.getDictText());
            } else if ("link_down".equals(fieldShowType)) {
                LinkDownProperty linkDownProperty2 = new LinkDownProperty(str1, str2, onlCgformField.getDictTable());
                a(linkDownProperty2, paramList1, arrayList3);
                commonProperty = linkDownProperty2;
            } else if ("sel_tree".equals(fieldShowType)) {

                String str4 = onlCgformField.getDictText();
                String[] arrayOfString = str4.split(",");
                String str5 = onlCgformField.getDictTable() + "," + arrayOfString[2] + "," + arrayOfString[0];
                TreeSelectProperty treeSelectProperty2 = new TreeSelectProperty(str1, str2, str5, arrayOfString[1], onlCgformField.getDictField());
                if (arrayOfString.length > 3) {
                    treeSelectProperty2.setHasChildField(arrayOfString[3]);
                }
                commonProperty = treeSelectProperty2;
            } else if ("cat_tree".equals(fieldShowType)) {

                String str4 = onlCgformField.getDictText();
                String str5 = onlCgformField.getDictField();
                String str6 = "0";
                if (oConvertUtils.isNotEmpty(str5) && !"0".equals(str5)) {
                    str6 = onlCgformHeadMapper.queryCategoryIdByCode(str5);
                }
                if (oConvertUtils.isEmpty(str4)) {

                    commonProperty = new TreeSelectProperty(str1, str2, str6);
                } else {

                    commonProperty= new TreeSelectProperty(str1, str2, str6, str4);
                    HiddenProperty hiddenProperty = new HiddenProperty(str4, str4);
                    arrayList2.add(hiddenProperty);
                }

            } else if (paramf != null && str1.equals(paramf.getFieldName())) {

                String str = paramf.getTableName() + "," + paramf.getTextField() + "," + paramf.getCodeField();
                TreeSelectProperty treeSelectProperty2 = new TreeSelectProperty(str1, str2, str, paramf.getPidField(), paramf.getPidValue());
                treeSelectProperty2.setHasChildField(paramf.getHsaChildField());
                treeSelectProperty2.setPidComponent(Integer.valueOf(1));
                commonProperty = treeSelectProperty2;
            } else {
                StringProperty stringProperty1 = new StringProperty(str1, str2, fieldShowType, onlCgformField.getDbLength());

                if (oConvertUtils.isNotEmpty(onlCgformField.getFieldValidType())) {
                    CgformValidPatternEnum cgformValidPatternEnum = CgformValidPatternEnum.getPatternInfoByType(onlCgformField.getFieldValidType());
                    if (cgformValidPatternEnum != null) {
                        if (CgformValidPatternEnum.NOTNULL == cgformValidPatternEnum) {
                            arrayList1.add(str1);
                        } else {
                            stringProperty1.setPattern(cgformValidPatternEnum.getPattern());
                            stringProperty1.setErrorInfo(cgformValidPatternEnum.getMsg());
                        }
                    } else {

                        stringProperty1.setPattern(onlCgformField.getFieldValidType());
                        stringProperty1.setErrorInfo("输入的值不合法");
                    }
                }

                commonProperty = stringProperty1;
            }


            if (onlCgformField.getIsReadOnly().intValue() == 1 || (paramList2 != null && paramList2.indexOf(str1) >= 0)) {
                commonProperty.setDisabled(true);
            }

            commonProperty.setOrder(onlCgformField.getOrderNum());
            commonProperty.setDefVal(onlCgformField.getFieldDefaultValue());
            arrayList2.add(commonProperty);
        }
        if (arrayList1.size() > 0) {
            JsonSchemaDescrip jsonSchemaDescrip = new JsonSchemaDescrip(arrayList1);
            jSONObject = JsonschemaUtil.getJsonSchema(jsonSchemaDescrip, arrayList2);
        } else {
            JsonSchemaDescrip jsonSchemaDescrip = new JsonSchemaDescrip();
            jSONObject = JsonschemaUtil.getJsonSchema(jsonSchemaDescrip, arrayList2);
        }
        return jSONObject;
    }


    public static JSONObject b(String paramString, List<OnlCgformField> paramList) {
//        null = new JSONObject();
        ArrayList<String> arrayList1 = new ArrayList<>();
        ArrayList<CommonProperty> arrayList2 = new ArrayList<>();
        ISysBaseAPI iSysBaseAPI = (ISysBaseAPI) SpringContextUtils.getBean(ISysBaseAPI.class);
        for (OnlCgformField onlCgformField : paramList) {
            String str1 = onlCgformField.getDbFieldName();
            if ("id".equals(str1)) {
                continue;
            }
            String str2 = onlCgformField.getDbFieldTxt();

            if ("1".equals(onlCgformField.getFieldMustInput())) {
                arrayList1.add(str1);
            }
            String str3 = onlCgformField.getFieldShowType();


            String str4 = onlCgformField.getDictField();
            CommonProperty stringProperty = null;
            if (org.dfzt.modules.online.cgform.util.i.a(onlCgformField.getDbType())) {
                stringProperty = new NumberProperty(str1, str2, "number");
            } else if (c(str3)) {
                List list = iSysBaseAPI.queryDictItemsByCode(str4);
                StringProperty stringProperty1 = new StringProperty(str1, str2, str3, onlCgformField.getDbLength(), list);
            } else {
                stringProperty = new StringProperty(str1, str2, str3, onlCgformField.getDbLength());
            }

            stringProperty.setOrder(onlCgformField.getOrderNum());
            arrayList2.add(stringProperty);
        }
        return JsonschemaUtil.getSubJsonSchema(paramString, arrayList1, arrayList2);
    }


    public static Set<String> a(List<OnlCgformField> paramList) {
        HashSet hashSet = new HashSet();
        for (OnlCgformField onlCgformField : paramList) {
            if ("popup".equals(onlCgformField.getFieldShowType())) {
                String str = onlCgformField.getDictText();
                if (str != null && !str.equals("")) {
                    hashSet.addAll((Collection) Arrays.stream(str.split(",")).collect(Collectors.toSet()));
                }
            }
            if ("cat_tree".equals(onlCgformField.getFieldShowType())) {
                String str = onlCgformField.getDictText();
                if (oConvertUtils.isNotEmpty(str)) {
                    hashSet.add(str);
                }
            }
        }
        for (OnlCgformField onlCgformField : paramList) {
            String str = onlCgformField.getDbFieldName();
            if (onlCgformField.getIsShowForm().intValue() == 1 && hashSet.contains(str)) {
                hashSet.remove(str);
            }
        }
        return hashSet;
    }


    public static Map<String, Object> a(String paramString, List<OnlCgformField> paramList, JSONObject paramJSONObject) {
        StringBuffer stringBuffer1 = new StringBuffer();
        StringBuffer stringBuffer2 = new StringBuffer();
        String str1 = "";
        try {
            str1 = org.dfzt.modules.online.config.util.d.getDatabaseType();
        } catch (SQLException sQLException) {
            sQLException.printStackTrace();
        } catch (DBException dBException) {
            dBException.printStackTrace();
        }
        HashMap hashMap = new HashMap();
        boolean bool = false;
        String str2 = null;
        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        if (loginUser == null) {
            throw new SpringBootException("online保存表单数据异常:系统未找到当前登陆用户信息");
        }


        Set set = a(paramList);


        for (OnlCgformField onlCgformField : paramList) {
            String str4 = onlCgformField.getDbFieldName();
            if (null == str4) {
                as.info("--------online保存表单数据遇见空名称的字段------->>" + onlCgformField.getId());

                continue;
            }
            if ("id".equals(str4.toLowerCase())) {
                bool = true;
                str2 = paramJSONObject.getString(str4);

                continue;
            }

            a(onlCgformField, loginUser, paramJSONObject, new String[]{"CREATE_BY", "CREATE_TIME", "SYS_ORG_CODE"});


            if ("bpm_status".equals(str4.toLowerCase())) {
                stringBuffer1.append("," + str4);
                stringBuffer2.append(",'1'");

                continue;
            }

            if (set.contains(str4)) {

                stringBuffer1.append("," + str4);

                String str = org.dfzt.modules.online.cgform.util.i.a(str1, onlCgformField, paramJSONObject, hashMap);
                stringBuffer2.append("," + str);

                continue;
            }

            if (onlCgformField.getIsShowForm().intValue() != 1 && oConvertUtils.isEmpty(onlCgformField.getMainField()) &&
                    oConvertUtils.isEmpty(onlCgformField.getDbDefaultVal())) {
                continue;
            }


            if (paramJSONObject.get(str4) == null) {
                if (oConvertUtils.isEmpty(onlCgformField.getDbDefaultVal())) {
                    continue;
                }
                paramJSONObject.put(str4, onlCgformField.getDbDefaultVal());
            }


            if ("".equals(paramJSONObject.get(str4))) {
                String str = onlCgformField.getDbType();
                if (org.dfzt.modules.online.cgform.util.i.a(str) || org.dfzt.modules.online.cgform.util.i.b(str)) {
                    continue;
                }
            }


            stringBuffer1.append("," + str4);


            String str5 = org.dfzt.modules.online.cgform.util.i.a(str1, onlCgformField, paramJSONObject, hashMap);
            stringBuffer2.append("," + str5);
        }

        if (bool) {
            if (oConvertUtils.isEmpty(str2)) {
                str2 = a();
            }
        } else {
            str2 = a();
        }
        String str3 = "insert into " + f(paramString) + "(" + "id" + stringBuffer1.toString() + ") values(" + "'" + str2 + "'" + stringBuffer2.toString() + ")";
        hashMap.put("execute_sql_string", str3);
        as.info("--动态表单保存sql-->" + str3);
        return hashMap;
    }


    public static Map<String, Object> b(String paramString, List<OnlCgformField> paramList, JSONObject paramJSONObject) {
        StringBuffer stringBuffer = new StringBuffer();
        HashMap hashMap = new HashMap();
        String str1 = "";
        try {
            str1 = org.dfzt.modules.online.config.util.d.getDatabaseType();
        } catch (SQLException sQLException) {
            sQLException.printStackTrace();
        } catch (DBException dBException) {
            dBException.printStackTrace();
        }

        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        if (loginUser == null) {
            throw new SpringBootException("online修改表单数据异常:系统未找到当前登陆用户信息");
        }


        Set set = a(paramList);


        for (OnlCgformField onlCgformField : paramList) {
            String str4 = onlCgformField.getDbFieldName();
            if (null == str4) {
                as.info("--------online修改表单数据遇见空名称的字段------->>" + onlCgformField.getId());

                continue;
            }

            a(onlCgformField, loginUser, paramJSONObject, new String[]{"UPDATE_BY", "UPDATE_TIME", "SYS_ORG_CODE"});


            if (set.contains(str4)) {
                if (paramJSONObject.get(str4) != null && !"".equals(paramJSONObject.getString(str4))) {
                    String str = org.dfzt.modules.online.cgform.util.i.a(str1, onlCgformField, paramJSONObject, hashMap);
                    stringBuffer.append(str4 + "=" + str + ",");

                    continue;
                }
            }

            if (onlCgformField.getIsShowForm().intValue() != 1) {
                continue;
            }

            if ("id".equals(str4)) {
                continue;
            }

            if ("".equals(paramJSONObject.get(str4))) {
                String str = onlCgformField.getDbType();
                if (org.dfzt.modules.online.cgform.util.i.a(str) || org.dfzt.modules.online.cgform.util.i.b(str)) {
                    continue;
                }
            }

            String str5 = org.dfzt.modules.online.cgform.util.i.a(str1, onlCgformField, paramJSONObject, hashMap);
            stringBuffer.append(str4 + "=" + str5 + ",");
        }


        String str2 = stringBuffer.toString();
        if (str2.endsWith(",")) {
            str2 = str2.substring(0, str2.length() - 1);
        }
        String str3 = "update " + f(paramString) + " set " + str2 + " where 1=1  " + " AND " + "id" + "=" + "'" + paramJSONObject.getString("id") + "'";
        as.info("--动态表单编辑sql-->" + str3);
        hashMap.put("execute_sql_string", str3);
        return hashMap;
    }


    public static String a(String paramString1, List<OnlCgformField> paramList, String paramString2) {
        return a(paramString1, paramList, "id", paramString2);
    }


    public static String a(String paramString1, List<OnlCgformField> paramList, String paramString2, String paramString3) {
        StringBuffer stringBuffer = new StringBuffer();

        stringBuffer.append("SELECT ");
        int i1 = paramList.size();
        boolean bool = false;
        for (byte b1 = 0; b1 < i1; b1++) {
            String str = ((OnlCgformField) paramList.get(b1)).getDbFieldName();
            if ("id".equals(str)) {
                bool = true;
            }
            stringBuffer.append(str);
            if (i1 > b1 + 1) {
                stringBuffer.append(",");
            }
        }
        if (!bool) {
            stringBuffer.append(",id");
        }
        stringBuffer.append(" FROM " + f(paramString1) + " where 1=1  " + " AND " + paramString2 + "=" + "'" + paramString3 + "'");
        return stringBuffer.toString();
    }


    public static void a(OnlCgformField paramOnlCgformField, LoginUser paramLoginUser, JSONObject paramJSONObject, String... paramVarArgs) {
        String str = paramOnlCgformField.getDbFieldName();
        boolean bool = false;
        for (String str1 : paramVarArgs) {
            if (str.toUpperCase().equals(str1)) {
                if (paramOnlCgformField.getIsShowForm().intValue() == 1) {
                    if (paramJSONObject.get(str) == null) {
                        bool = true;
                    }
                } else {
                    paramOnlCgformField.setIsShowForm(Integer.valueOf(1));
                    bool = true;
                }
                if (bool) {
                    switch (str1) {
                        case "CREATE_BY":
                            paramJSONObject.put(str, paramLoginUser.getUsername());
                            break;
                        case "CREATE_TIME":
                            paramOnlCgformField.setFieldShowType("datetime");
                            paramJSONObject.put(str, DateUtils.formatDateTime());
                            break;
                        case "UPDATE_BY":
                            paramJSONObject.put(str, paramLoginUser.getUsername());
                            break;
                        case "UPDATE_TIME":
                            paramOnlCgformField.setFieldShowType("datetime");
                            paramJSONObject.put(str, DateUtils.formatDateTime());
                            break;
                        case "SYS_ORG_CODE":
                            paramJSONObject.put(str, paramLoginUser.getOrgCode());
                            break;
                    }
                }
                break;
            }
        }
    }


    public static boolean a(Object paramObject1, Object paramObject2) {
        if (oConvertUtils.isEmpty(paramObject1) && oConvertUtils.isEmpty(paramObject2)) {
            return true;
        }
        if (oConvertUtils.isNotEmpty(paramObject1) && paramObject1.equals(paramObject2)) {
            return true;
        }

        return false;
    }


    public static boolean a(OnlCgformField paramOnlCgformField1, OnlCgformField paramOnlCgformField2) {
        if (!a((Object) paramOnlCgformField1.getDbFieldName(), paramOnlCgformField2.getDbFieldName()) ||
                !a((Object) paramOnlCgformField1.getDbFieldTxt(), paramOnlCgformField2.getDbFieldTxt()) ||
                !a((Object) paramOnlCgformField1.getDbLength(), paramOnlCgformField2.getDbLength()) ||
                !a((Object) paramOnlCgformField1.getDbPointLength(), paramOnlCgformField2.getDbPointLength()) ||
                !a((Object) paramOnlCgformField1.getDbType(), paramOnlCgformField2.getDbType()) ||
                !a(paramOnlCgformField1.getDbIsNull(), paramOnlCgformField2.getDbIsNull()) ||

                !a(paramOnlCgformField1.getDbIsKey(), paramOnlCgformField2.getDbIsKey()) ||


                !a((Object) paramOnlCgformField1.getDbDefaultVal(), paramOnlCgformField2.getDbDefaultVal())) {
            return true;
        }
        return false;
    }


    public static boolean a(OnlCgformIndex paramOnlCgformIndex1, OnlCgformIndex paramOnlCgformIndex2) {
        if (!a((Object) paramOnlCgformIndex1.getIndexName(), paramOnlCgformIndex2.getIndexName()) ||
                !a((Object) paramOnlCgformIndex1.getIndexField(), paramOnlCgformIndex2.getIndexField()) ||
                !a((Object) paramOnlCgformIndex1.getIndexType(), paramOnlCgformIndex2.getIndexType())) {
            return true;
        }
        return false;
    }


    public static boolean a(OnlCgformHead paramOnlCgformHead1, OnlCgformHead paramOnlCgformHead2) {
        if (!a((Object) paramOnlCgformHead1.getTableName(), paramOnlCgformHead2.getTableName()) || !a((Object) paramOnlCgformHead1.getTableTxt(), paramOnlCgformHead2.getTableTxt())) {
            return true;
        }
        return false;
    }


    public static String a(String paramString, List<OnlCgformField> paramList, Map<String, Object> paramMap) {
        StringBuffer stringBuffer1 = new StringBuffer();
        StringBuffer stringBuffer2 = new StringBuffer();
        for (OnlCgformField onlCgformField : paramList) {
            String str1 = onlCgformField.getDbFieldName();
            String str2 = onlCgformField.getDbType();
            if (onlCgformField.getIsShowList().intValue() == 1) {
                stringBuffer2.append("," + str1);
            }


            if (oConvertUtils.isNotEmpty(onlCgformField.getMainField())) {
                boolean bool = !org.dfzt.modules.online.cgform.util.i.a(str2);
                String str = QueryGenerator.getSingleQueryConditionSql(str1, "", paramMap.get(str1), bool);
                if (!"".equals(str)) {
                    stringBuffer1.append(" AND " + str);
                }
            }


            if (onlCgformField.getIsQuery().intValue() == 1) {
                if ("single".equals(onlCgformField.getQueryMode())) {

                    if (paramMap.get(str1) == null) {
                        continue;
                    }
                    boolean bool = !org.dfzt.modules.online.cgform.util.i.a(str2);
                    String str = QueryGenerator.getSingleQueryConditionSql(str1, "", paramMap.get(str1), bool);
                    if ("".equals(str)) {
                        continue;
                    }
                    stringBuffer1.append(" AND " + str);
                    continue;
                }
                Object object1 = paramMap.get(str1 + "_begin");
                if (object1 != null) {
                    stringBuffer1.append(" AND " + str1 + ">=");
                    if (org.dfzt.modules.online.cgform.util.i.a(str2)) {
                        stringBuffer1.append(object1.toString());
                    } else {
                        stringBuffer1.append("'" + object1.toString() + "'");
                    }
                }
                Object object2 = paramMap.get(str1 + "_end");
                if (object2 != null) {
                    stringBuffer1.append(" AND " + str1 + "<=");
                    if (org.dfzt.modules.online.cgform.util.i.a(str2)) {
                        stringBuffer1.append(object2.toString());
                        continue;
                    }
                    stringBuffer1.append("'" + object2.toString() + "'");
                }
            }
        }


        return "SELECT id" + stringBuffer2.toString() + " FROM " + f(paramString) + " where 1=1  " + stringBuffer1.toString();
    }


    public static List<ExcelExportEntity> a(List<OnlCgformField> paramList, String paramString) {
        ArrayList arrayList = new ArrayList();
        for (byte b1 = 0; b1 < paramList.size(); b1++) {
            if (null == paramString || !paramString.equals(((OnlCgformField) paramList.get(b1)).getDbFieldName())) {

                if (((OnlCgformField) paramList.get(b1)).getIsShowList().intValue() == 1) {
                    ExcelExportEntity excelExportEntity = new ExcelExportEntity(((OnlCgformField) paramList.get(b1)).getDbFieldTxt(), ((OnlCgformField) paramList.get(b1)).getDbFieldName());
                    int b2 = (((OnlCgformField) paramList.get(b1)).getDbLength().intValue() == 0) ? 12 : ((((OnlCgformField) paramList.get(b1)).getDbLength().intValue() > 30) ? 30 : ((OnlCgformField) paramList.get(b1)).getDbLength().intValue());
                    if (((OnlCgformField) paramList.get(b1)).getFieldShowType().equals("date")) {
                        excelExportEntity.setFormat("yyyy-MM-dd");
                    } else if (((OnlCgformField) paramList.get(b1)).getFieldShowType().equals("datetime")) {
                        excelExportEntity.setFormat("yyyy-MM-dd HH:mm:ss");
                    }
                    if (b2 < 10) {
                        b2 = 10;
                    }
                    excelExportEntity.setWidth(b2);
                    arrayList.add(excelExportEntity);
                }
            }
        }
        return arrayList;
    }


    public static boolean a(OnlCgformEnhanceJava paramOnlCgformEnhanceJava) {
        String str1 = paramOnlCgformEnhanceJava.getCgJavaType();
        String str2 = paramOnlCgformEnhanceJava.getCgJavaValue();
        if (oConvertUtils.isNotEmpty(str2)) {
            try {
                if ("class".equals(str1)) {
                    Class clazz = Class.forName(str2);
                    if (clazz == null || clazz.newInstance() == null) {
                        return false;
                    }
                }

                if ("spring".equals(str1)) {
                    Object object = SpringContextUtils.getBean(str2);
                    if (object == null) {
                        return false;
                    }
                }
            } catch (Exception exception) {
                as.error(exception.getMessage(), exception);
                return false;
            }
        }
        return true;
    }


    public static void b(List<String> paramList) {
        Collections.sort(paramList, (param1String1, param1String2) -> {
            if (param1String1 == null || param1String2 == null) {
                return -1;
            }
            if (param1String1.compareTo(param1String2) > 0) {
                return 1;
            }
            if (param1String1.compareTo(param1String2) < 0) {
                return -1;
            }
            if (param1String1.compareTo(param1String2) == 0) {
                return 0;
            }
            return 0;
        });
    }


    public static void c(List<String> paramList) {
        Collections.sort(paramList, (param1String1, param1String2) -> {
            if (param1String1 == null || param1String2 == null) {
                return -1;
            }
            if (param1String1.length() > param1String2.length()) {
                return 1;
            }
            if (param1String1.length() < param1String2.length()) {
                return -1;
            }
            if (param1String1.compareTo(param1String2) > 0) {
                return 1;
            }
            if (param1String1.compareTo(param1String2) < 0) {
                return -1;
            }
            if (param1String1.compareTo(param1String2) == 0) {
                return 0;
            }
            return 0;
        });
    }


    private static String a(String paramString, boolean paramBoolean) {
        if (paramBoolean) {
            return "'" + QueryGenerator.converRuleValue(paramString) + "'";
        }
        return QueryGenerator.converRuleValue(paramString);
    }


    private static void a(String paramString1, SysPermissionDataRuleModel paramSysPermissionDataRuleModel, String paramString2, String paramString3, StringBuffer paramStringBuffer) {
        QueryRuleEnum queryRuleEnum = QueryRuleEnum.getByValue(paramSysPermissionDataRuleModel.getRuleConditions());
        boolean bool = !org.dfzt.modules.online.cgform.util.i.a(paramString3);
        String str = a(paramSysPermissionDataRuleModel.getRuleValue(), bool);
        if (str == null || queryRuleEnum == null) {
            return;
        }


        if ("ORACLE".equalsIgnoreCase(paramString1) &&
                "Date".equals(paramString3)) {
            str = str.replace("'", "");
            if (str.length() == 10) {
                str = b(str);
            } else {
                str = a(str);
            }
        }

        //todo 注释switch 选择器有问题 fr
        /*switch (null.a[queryRuleEnum.ordinal()]) {
            case 1:
                paramStringBuffer.append(" AND " + paramString2 + ">" + str);
                return;
            case 2:
                paramStringBuffer.append(" AND " + paramString2 + ">=" + str);
                return;
            case 3:
                paramStringBuffer.append(" AND " + paramString2 + "<" + str);
                return;
            case 4:
                paramStringBuffer.append(" AND " + paramString2 + "<=" + str);
                return;
            case 10:
                paramStringBuffer.append(" AND " + paramString2 + "=" + str);
                return;
            case 5:
                paramStringBuffer.append(" AND " + paramString2 + " <> " + str);
                return;
            case 6:
                paramStringBuffer.append(" AND " + paramString2 + " IN " + str);
                return;
            case 7:
                paramStringBuffer.append(" AND " + paramString2 + " LIKE '%" + QueryGenerator.trimSingleQuote(str) + "%'");
                return;
            case 8:
                paramStringBuffer.append(" AND " + paramString2 + " LIKE '%" + QueryGenerator.trimSingleQuote(str) + "'");
                return;
            case 9:
                paramStringBuffer.append(" AND " + paramString2 + " LIKE '" + QueryGenerator.trimSingleQuote(str) + "%'");
                return;
        }*/
        as.info("--查询规则未匹配到---");
    }


    public static String a(String paramString, JSONObject paramJSONObject) {
        if (paramJSONObject == null) {
            return paramString;
        }
        paramString = paramString.replace("#{UUID}", UUIDGenerator.generate());
        Set<String> set = QueryGenerator.getSqlRuleParams(paramString);

        for (String str1 : set) {
            if (paramJSONObject.get(str1.toUpperCase()) == null && paramJSONObject.get(str1.toLowerCase()) == null) {
                String str = QueryGenerator.converRuleValue(str1);
                paramString = paramString.replace("#{" + str1 + "}", str);
                continue;
            }
            String str2 = null;
            if (paramJSONObject.containsKey(str1.toLowerCase())) {
                str2 = paramJSONObject.getString(str1.toLowerCase());
            } else if (paramJSONObject.containsKey(str1.toUpperCase())) {
                str2 = paramJSONObject.getString(str1.toUpperCase());
            }
            paramString = paramString.replace("#{" + str1 + "}", str2);
        }

        return paramString;
    }


    public static String c(String paramString, List<OnlCgformButton> paramList) {
        paramString = d(paramString, paramList);
        for (String str : "beforeAdd,beforeEdit,afterAdd,afterEdit,beforeDelete,afterDelete,mounted,created".split(",")) {
            if ("beforeAdd,afterAdd,mounted,created".indexOf(str) >= 0) {
                Pattern pattern = Pattern.compile("(" + str + "\\s*\\(\\)\\s*\\{)");
                Matcher matcher = pattern.matcher(paramString);
                if (matcher.find()) {
                    paramString = paramString.replace(matcher.group(0), str + "(that){const getAction=this._getAction,postAction=this._postAction,deleteAction=this._deleteAction;");
                }
            } else {
                Pattern pattern = Pattern.compile("(" + str + "\\s*\\(row\\)\\s*\\{)");
                Matcher matcher = pattern.matcher(paramString);
                if (matcher.find()) {
                    paramString = paramString.replace(matcher.group(0), str + "(that,row){const getAction=this._getAction,postAction=this._postAction,deleteAction=this._deleteAction;");
                } else {
                    Pattern pattern1 = Pattern.compile("(" + str + "\\s*\\(\\)\\s*\\{)");
                    Matcher matcher1 = pattern1.matcher(paramString);
                    if (matcher1.find()) {
                        paramString = paramString.replace(matcher1.group(0), str + "(that){const getAction=this._getAction,postAction=this._postAction,deleteAction=this._deleteAction;");
                    }
                }
            }
        }
        return d(paramString);
    }


    public static void a(OnlCgformEnhanceJs paramOnlCgformEnhanceJs, String paramString, List<OnlCgformField> paramList) {
        if (paramOnlCgformEnhanceJs == null || oConvertUtils.isEmpty(paramOnlCgformEnhanceJs.getCgJs())) {
            return;
        }
        String str1 = paramOnlCgformEnhanceJs.getCgJs();
        String str2 = "onlChange";
        Pattern pattern = Pattern.compile("(" + paramString + "_" + str2 + "\\s*\\(\\)\\s*\\{)");
        Matcher matcher = pattern.matcher(str1);
        if (matcher.find()) {
            str1 = str1.replace(matcher.group(0), paramString + "_" + str2 + "(){const getAction=this._getAction,postAction=this._postAction,deleteAction=this._deleteAction;");
            for (OnlCgformField onlCgformField : paramList) {
                Pattern pattern1 = Pattern.compile("(" + onlCgformField.getDbFieldName() + "\\s*\\(\\))");
                Matcher matcher1 = pattern1.matcher(str1);
                if (matcher1.find()) {
                    str1 = str1.replace(matcher1.group(0), onlCgformField.getDbFieldName() + "(that,event)");
                }
            }
        }
        paramOnlCgformEnhanceJs.setCgJs(str1);
    }


    public static void a(OnlCgformEnhanceJs paramOnlCgformEnhanceJs, String paramString, List<OnlCgformField> paramList, boolean paramBoolean) {
        if (paramOnlCgformEnhanceJs == null || oConvertUtils.isEmpty(paramOnlCgformEnhanceJs.getCgJs())) {
            return;
        }
        String str1 = paramOnlCgformEnhanceJs.getCgJs();
        String str2 = "onlChange";
        Pattern pattern = Pattern.compile("([^_]" + str2 + "\\s*\\(\\)\\s*\\{)");
        Matcher matcher = pattern.matcher(str1);
        if (matcher.find()) {
            str1 = str1.replace(matcher.group(0), str2 + "(){const getAction=this._getAction,postAction=this._postAction,deleteAction=this._deleteAction;");
            for (OnlCgformField onlCgformField : paramList) {
                Pattern pattern1 = Pattern.compile("(" + onlCgformField.getDbFieldName() + "\\s*\\(\\))");
                Matcher matcher1 = pattern1.matcher(str1);
                if (matcher1.find()) {
                    str1 = str1.replace(matcher1.group(0), onlCgformField.getDbFieldName() + "(that,event)");
                }
            }
        }
        paramOnlCgformEnhanceJs.setCgJs(str1);
        a(paramOnlCgformEnhanceJs);
        a(paramOnlCgformEnhanceJs, paramString, paramList);
    }

    public static void a(OnlCgformEnhanceJs paramOnlCgformEnhanceJs) {
        String str1 = paramOnlCgformEnhanceJs.getCgJs();
        String str2 = "show";
        Pattern pattern = Pattern.compile("(" + str2 + "\\s*\\(\\)\\s*\\{)");
        Matcher matcher = pattern.matcher(str1);
        if (matcher.find()) {
            str1 = str1.replace(matcher.group(0), str2 + "(that){const getAction=this._getAction,postAction=this._postAction,deleteAction=this._deleteAction;");
        }
        paramOnlCgformEnhanceJs.setCgJs(str1);
    }


    public static String d(String paramString) {
        as.info("最终的增强JS" + paramString);
        return "class OnlineEnhanceJs{constructor(getAction,postAction,deleteAction){this._getAction=getAction;this._postAction=postAction;this._deleteAction=deleteAction;}" + paramString + "}";
    }


    public static String d(String paramString, List<OnlCgformButton> paramList) {
        if (paramList != null) {
            for (OnlCgformButton onlCgformButton : paramList) {
                String str = onlCgformButton.getButtonCode();
                if ("link".equals(onlCgformButton.getButtonStyle())) {
                    Pattern pattern1 = Pattern.compile("(" + str + "\\s*\\(row\\)\\s*\\{)");
                    Matcher matcher1 = pattern1.matcher(paramString);
                    if (matcher1.find()) {
                        paramString = paramString.replace(matcher1.group(0), str + "(that,row){const getAction=this._getAction,postAction=this._postAction,deleteAction=this._deleteAction;");
                        continue;
                    }
                    Pattern pattern2 = Pattern.compile("(" + str + "\\s*\\(\\)\\s*\\{)");
                    Matcher matcher2 = pattern2.matcher(paramString);
                    if (matcher2.find()) {
                        paramString = paramString.replace(matcher2.group(0), str + "(that){const getAction=this._getAction,postAction=this._postAction,deleteAction=this._deleteAction;");
                    }
                    continue;
                }
                if ("button".equals(onlCgformButton.getButtonStyle()) || "form".equals(onlCgformButton.getButtonStyle())) {
                    Pattern pattern = Pattern.compile("(" + str + "\\s*\\(\\)\\s*\\{)");
                    Matcher matcher = pattern.matcher(paramString);
                    if (matcher.find()) {
                        paramString = paramString.replace(matcher.group(0), str + "(that){const getAction=this._getAction,postAction=this._postAction,deleteAction=this._deleteAction;");
                    }
                }
            }
        }
        return paramString;
    }


    public static JSONArray a(List<OnlCgformField> paramList1, List<String> paramList2) {
        JSONArray jSONArray = new JSONArray();
        ISysBaseAPI iSysBaseAPI = (ISysBaseAPI) SpringContextUtils.getBean(ISysBaseAPI.class);
        for (OnlCgformField onlCgformField : paramList1) {
            String str1 = onlCgformField.getDbFieldName();
            if ("id".equals(str1)) {
                continue;
            }
            JSONObject jSONObject = new JSONObject();
            if (paramList2.indexOf(str1) >= 0) {
                jSONObject.put("disabled", Boolean.valueOf(true));
            }
            jSONObject.put("title", onlCgformField.getDbFieldTxt());
            jSONObject.put("key", str1);
            jSONObject.put("width", "186px");

            String str2 = b(onlCgformField);
            jSONObject.put("type", str2);
            if (str2.equals("file") || str2.equals("image")) {
                jSONObject.put("responseName", "message");
                jSONObject.put("token", Boolean.valueOf(true));
            }
            if (str2.equals("switch")) {
                jSONObject.put("type", "checkbox");
                JSONArray jSONArray1 = new JSONArray();
                if (oConvertUtils.isEmpty(onlCgformField.getFieldExtendJson())) {
                    jSONArray1.add("Y");
                    jSONArray1.add("N");
                } else {
                    jSONArray1 = JSONArray.parseArray(onlCgformField.getFieldExtendJson());
                }
                jSONObject.put("customValue", jSONArray1);
            }
            if (str2.equals("popup")) {
                jSONObject.put("popupCode", onlCgformField.getDictTable());
                jSONObject.put("orgFields", onlCgformField.getDictField());
                jSONObject.put("destFields", onlCgformField.getDictText());
                String str = onlCgformField.getDictText();
                if (str != null && !str.equals("")) {
                    ArrayList arrayList = new ArrayList();
                    String[] arrayOfString = str.split(",");
                    for (String str3 : arrayOfString) {
                        if (!a(str3, paramList1)) {


                            arrayList.add(str3);
                            JSONObject jSONObject1 = new JSONObject();
                            jSONObject1.put("title", str3);
                            jSONObject1.put("key", str3);
                            jSONObject1.put("type", "hidden");
                            jSONArray.add(jSONObject1);
                        }
                    }
                }
            }

            jSONObject.put("defaultValue", onlCgformField.getDbDefaultVal());
            jSONObject.put("fieldDefaultValue", onlCgformField.getFieldDefaultValue());
            jSONObject.put("placeholder", "请输入" + onlCgformField.getDbFieldTxt());
            jSONObject.put("validateRules", a(onlCgformField));

            if ("list".equals(onlCgformField.getFieldShowType()) || "radio"
                    .equals(onlCgformField.getFieldShowType()) || "checkbox_meta"
                    .equals(onlCgformField.getFieldShowType()) || "list_multi"
                    .equals(onlCgformField.getFieldShowType()) || "sel_search"
                    .equals(onlCgformField.getFieldShowType())) {
                List list = new ArrayList();
                if (oConvertUtils.isNotEmpty(onlCgformField.getDictTable())) {
                    List list1 = iSysBaseAPI.queryTableDictItemsByCode(onlCgformField.getDictTable(), onlCgformField.getDictText(), onlCgformField.getDictField());
                } else if (oConvertUtils.isNotEmpty(onlCgformField.getDictField())) {
                    list = iSysBaseAPI.queryDictItemsByCode(onlCgformField.getDictField());
                }


                jSONObject.put("options", list);
                if ("list_multi".equals(onlCgformField.getFieldShowType())) {
                    jSONObject.put("width", "230px");
                }
            }
            jSONArray.add(jSONObject);
        }
        return jSONArray;
    }


    private static JSONArray a(OnlCgformField paramOnlCgformField) {
        JSONArray jSONArray = new JSONArray();
        if (paramOnlCgformField.getDbIsNull().intValue() == 0 || "1".equals(paramOnlCgformField.getFieldMustInput())) {
            JSONObject jSONObject = new JSONObject();
            jSONObject.put("required", Boolean.valueOf(true));
            jSONObject.put("message", paramOnlCgformField.getDbFieldTxt() + "不能为空!");
            jSONArray.add(jSONObject);
        }
        if (oConvertUtils.isNotEmpty(paramOnlCgformField.getFieldValidType())) {
            JSONObject jSONObject = new JSONObject();
            if ("only".equals(paramOnlCgformField.getFieldValidType())) {

                jSONObject.put("pattern", null);
            } else {
                jSONObject.put("pattern", paramOnlCgformField.getFieldValidType());
            }
            jSONObject.put("message", paramOnlCgformField.getDbFieldTxt() + "格式不正确");
            jSONArray.add(jSONObject);
        }
        return jSONArray;
    }


    public static Map<String, Object> b(Map<String, Object> paramMap) {
        HashMap<String, Object> hashMap = new HashMap<String, Object>();
        if (paramMap == null || paramMap.isEmpty()) {
            return hashMap;
        }
        Set<String> set = paramMap.keySet();
        for (String str1 : set) {


            Object object = paramMap.get(str1);
            if (object instanceof Clob) {
                object = a((Clob) object);
            } else if (object instanceof byte[]) {
                object = new String((byte[]) object);
            } else if (object instanceof Blob) {
                try {
                    Blob blob = (Blob) object;
                    object = new String(blob.getBytes(1L, (int) blob.length()), UTF_8);
                } catch (Exception exception) {
                    exception.printStackTrace();
                }
            }
            String str2 = str1.toLowerCase();
            hashMap.put(str2, object);
        }

        return hashMap;
    }


    public static JSONObject a(JSONObject paramJSONObject) {
        if (org.dfzt.modules.online.config.util.d.a()) {
            JSONObject jSONObject = new JSONObject();
            if (paramJSONObject == null || paramJSONObject.isEmpty()) {
                return jSONObject;
            }
            Set<String> set = paramJSONObject.keySet();
            for (String str1 : set) {
                String str2 = str1.toLowerCase();
                jSONObject.put(str2, paramJSONObject.get(str1));
            }
            return jSONObject;
        }
        return paramJSONObject;
    }


    public static List<Map<String, Object>> d(List<Map<String, Object>> paramList) {
        ArrayList<Map<String, Object>> arrayList = new ArrayList<Map<String, Object>>();
        for (Map<String, Object> map : paramList) {
            HashMap<String, Object> hashMap = new HashMap<String, Object>();
            Set<String> set = map.keySet();
            for (String str1 : set) {


                Object object = map.get(str1);
                if (object instanceof Clob) {
                    object = a((Clob) object);
                } else if (object instanceof byte[]) {
                    object = new String((byte[]) object);
                } else if (object instanceof Blob) {
                    try {
                        Blob blob = (Blob) object;
                        object = new String(blob.getBytes(1L, (int) blob.length()), "UTF-8");
                    } catch (Exception exception) {
                        exception.printStackTrace();
                    }
                }
                String str2 = str1.toLowerCase();
                hashMap.put(str2, object);
            }

            arrayList.add(hashMap);
        }
        return arrayList;
    }


    public static String a(Clob paramClob) {
        String str = "";
        try {
            Reader reader = paramClob.getCharacterStream();
            char[] arrayOfChar = new char[(int) paramClob.length()];
            reader.read(arrayOfChar);
            str = new String(arrayOfChar);
            reader.close();
        } catch (IOException | SQLException iOException) {
            iOException.printStackTrace();
        }
        return str;
    }


    public static Map<String, Object> c(String paramString, List<OnlCgformField> paramList, JSONObject paramJSONObject) {
        StringBuilder stringBuffer1 = new StringBuilder();
        StringBuilder stringBuffer2 = new StringBuilder();
        String str1 = "";
        try {
            str1 = org.dfzt.modules.online.config.util.d.getDatabaseType();
        } catch (SQLException | DBException sQLException) {
            sQLException.printStackTrace();
        }
        HashMap<String, Object> hashMap = new HashMap<String, Object>();
        boolean bool = false;
        String str2 = null;

        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        if (loginUser == null) {
            throw new SpringBootException("online保存表单数据异常:系统未找到当前登陆用户信息");
        }

        for (OnlCgformField onlCgformField : paramList) {
            String str4 = onlCgformField.getDbFieldName();
            if (null == str4) {
                as.info("--------online保存表单数据遇见空名称的字段------->>" + onlCgformField.getId());

                continue;
            }
            if (paramJSONObject.get(str4) == null && !"CREATE_BY".equalsIgnoreCase(str4) && !"CREATE_TIME".equalsIgnoreCase(str4) && !"SYS_ORG_CODE".equalsIgnoreCase(str4)) {
                continue;
            }


            a(onlCgformField, loginUser, paramJSONObject, "CREATE_BY", "CREATE_TIME", "SYS_ORG_CODE");


            if ("".equals(paramJSONObject.get(str4))) {
                String str = onlCgformField.getDbType();
                if (org.dfzt.modules.online.cgform.util.i.a(str) || org.dfzt.modules.online.cgform.util.i.b(str)) {
                    continue;
                }
            }
            if ("id".equals(str4.toLowerCase())) {
                bool = true;
                str2 = paramJSONObject.getString(str4);

                continue;
            }
            stringBuffer1.append(",").append(str4);

            String str5 = org.dfzt.modules.online.cgform.util.i.a(str1, onlCgformField, paramJSONObject, hashMap);
            stringBuffer2.append(",").append(str5);
        }
        if (!bool || oConvertUtils.isEmpty(str2)) {
            str2 = a();
        }
        String str3 = "insert into " + f(paramString) + "(" + "id" + stringBuffer1.toString() + ") values(" + "'" + str2 + "'" + stringBuffer2.toString() + ")";
        hashMap.put("execute_sql_string", str3);
        as.info("--表单设计器表单保存sql-->" + str3);
        return hashMap;
    }


    public static Map<String, Object> d(String paramString, List<OnlCgformField> paramList, JSONObject paramJSONObject) {
        StringBuilder stringBuffer = new StringBuilder();
        HashMap<String, Object> hashMap = new HashMap<String, Object>();
        String str1 = "";
        try {
            str1 = org.dfzt.modules.online.config.util.d.getDatabaseType();
        } catch (SQLException | DBException sQLException) {
            sQLException.printStackTrace();
        }
        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        if (loginUser == null) {
            throw new SpringBootException("online保存表单数据异常:系统未找到当前登陆用户信息");
        }
        for (OnlCgformField onlCgformField : paramList) {
            String str4 = onlCgformField.getDbFieldName();
            if (null == str4) {
                as.info("--------online修改表单数据遇见空名称的字段------->>" + onlCgformField.getId());

                continue;
            }
            if ("id".equals(str4)) {
                continue;
            }

            if (paramJSONObject.get(str4) == null && !"UPDATE_BY".equalsIgnoreCase(str4) && !"UPDATE_TIME".equalsIgnoreCase(str4) && !"SYS_ORG_CODE".equalsIgnoreCase(str4)) {
                continue;
            }


            a(onlCgformField, loginUser, paramJSONObject, "UPDATE_BY", "UPDATE_TIME", "SYS_ORG_CODE");


            if ("".equals(paramJSONObject.get(str4))) {
                String str = onlCgformField.getDbType();
                if (org.dfzt.modules.online.cgform.util.i.a(str) || org.dfzt.modules.online.cgform.util.i.b(str)) {
                    continue;
                }
            }
            String str5 = org.dfzt.modules.online.cgform.util.i.a(str1, onlCgformField, paramJSONObject, hashMap);
            stringBuffer.append(str4 + "=" + str5 + ",");
        }

        String str2 = stringBuffer.toString();
        if (str2.endsWith(",")) {
            str2 = str2.substring(0, str2.length() - 1);
        }
        String str3 = "update " + f(paramString) + " set " + str2 + " where 1=1  " + " AND " + "id" + "=" + "'" + paramJSONObject.getString("id") + "'";
        as.info("--表单设计器表单编辑sql-->" + str3);
        hashMap.put("execute_sql_string", str3);
        return hashMap;
    }


    public static Map<String, Object> a(String paramString1, String paramString2, String paramString3) {
        HashMap hashMap = new HashMap();
        String str = "update " + f(paramString1) + " set " + paramString2 + "=" + "'" + Character.MIN_VALUE + "'" + " where 1=1  " + " AND " + "id" + "=" + "'" + paramString3 + "'";
        as.info("--修改树节点状态：为无子节点sql-->" + str);
        hashMap.put("execute_sql_string", str);
        return hashMap;
    }


    public static String e(String paramString) {
        if (paramString == null || "".equals(paramString) || "0".equals(paramString)) {
            return "";
        }
        return "CODE like '" + paramString + "%" + "'";
    }


    public static String f(String paramString) {
        if (Pattern.matches("^[a-zA-z].*\\$\\d+$", paramString)) {
            return paramString.substring(0, paramString.lastIndexOf("$"));
        }
        return paramString;
    }


    public static void a(LinkDownProperty paramLinkDownProperty, List<OnlCgformField> paramList1, List<String> paramList2) {
        String str1 = paramLinkDownProperty.getDictTable();
        JSONObject jSONObject = JSONObject.parseObject(str1);
        String str2 = jSONObject.getString("linkField");
        ArrayList arrayList = new ArrayList();
        if (oConvertUtils.isNotEmpty(str2)) {
            String[] arrayOfString = str2.split(",");
            for (OnlCgformField onlCgformField : paramList1) {
                String str = onlCgformField.getDbFieldName();
                for (String str3 : arrayOfString) {
                    if (str3.equals(str)) {
                        paramList2.add(str);
                        arrayList.add(new BaseColumn(onlCgformField.getDbFieldTxt(), str));
                        break;
                    }
                }
            }
        }
        paramLinkDownProperty.setOtherColumns(arrayList);
    }


    public static String a(byte[] paramArrayOfByte, String paramString1, String paramString2, String paramString3) {
        return CommonUtils.uploadOnlineImage(paramArrayOfByte, paramString1, paramString2, paramString3);
    }


    public static List<String> e(List<OnlCgformField> paramList) {
        ArrayList arrayList = new ArrayList();
        for (OnlCgformField onlCgformField : paramList) {
            if ("image".equals(onlCgformField.getFieldShowType())) {
                arrayList.add(onlCgformField.getDbFieldTxt());
            }
        }
        return arrayList;
    }


    public static List<String> b(List<OnlCgformField> paramList, String paramString) {
        ArrayList arrayList = new ArrayList();
        for (OnlCgformField onlCgformField : paramList) {
            if ("image".equals(onlCgformField.getFieldShowType())) {
                arrayList.add(paramString + "_" + onlCgformField.getDbFieldTxt());
            }
        }
        return arrayList;
    }


    public static String a() {
        long l1 = IdWorker.getId();
        return String.valueOf(l1);
    }


    public static String a(Exception paramException) {
        String str = (paramException.getCause() != null) ? paramException.getCause().getMessage() : paramException.getMessage();
        if (str.indexOf("ORA-01452") != -1) {
            str = "ORA-01452: 无法 CREATE UNIQUE INDEX; 找到重复的关键字";
        } else if (str.indexOf("duplicate key") != -1) {
            str = "无法 CREATE UNIQUE INDEX; 找到重复的关键字";
        }
        return str;
    }


    private static String b(OnlCgformField paramOnlCgformField) {
        if ("checkbox".equals(paramOnlCgformField.getFieldShowType())) {
            return "checkbox";
        }
        if ("list".equals(paramOnlCgformField.getFieldShowType())) {
            return "select";
        }
        if ("switch".equals(paramOnlCgformField.getFieldShowType())) {
            return "switch";
        }
        if ("image".equals(paramOnlCgformField.getFieldShowType()) || "file"
                .equals(paramOnlCgformField.getFieldShowType()) || "radio"
                .equals(paramOnlCgformField.getFieldShowType()) || "popup"
                .equals(paramOnlCgformField.getFieldShowType()) || "list_multi"
                .equals(paramOnlCgformField.getFieldShowType()) || "sel_search"
                .equals(paramOnlCgformField.getFieldShowType())) {
            return paramOnlCgformField.getFieldShowType();
        }
        if ("datetime".equals(paramOnlCgformField.getFieldShowType())) {
            return "datetime";
        }
        if ("date".equals(paramOnlCgformField.getFieldShowType())) {
            return "date";
        }
        if ("int".equals(paramOnlCgformField.getDbType())) {
            return "inputNumber";
        }
        if ("double".equals(paramOnlCgformField.getDbType()) || "BigDecimal".equals(paramOnlCgformField.getDbType())) {
            return "inputNumber";
        }
        return "input";
    }


    private static String getDatabseType() {
        if (oConvertUtils.isNotEmpty(au)) {
            return au;
        }
        try {
            ISysBaseAPI iSysBaseAPI = (ISysBaseAPI) ApplicationContextUtil.getContext().getBean(ISysBaseAPI.class);
            au = iSysBaseAPI.getDatabaseType();
            return au;
        } catch (Exception exception) {
            exception.printStackTrace();

            return au;
        }
    }
}
